<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-08-06
 * Time: 14:07
 */

namespace App\Http\Controllers\Account;


use App\Http\Controllers\Controller;
use App\Http\Controllers\Validator\AdminVail;
use App\Model\Account\CreateTable;
use App\Tool\Error;
use Illuminate\Http\Request;

class CreateTableController extends Controller
{
    //返回所有系列表的状态
    public function getTableStatus(Request $request)
    {
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::getTableStatus($params['c_id']);
        return $this->success('ok', $status);
    }

    //创建客源表
    public function createCustomers(Request $request)
    {
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createCustomers($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //员工业绩统计表
    public function createAchievement(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createAchievement($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //合同表
    public function createContract(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createContract($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //合同诚意金表
    public function createCEM(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createCEM($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //规则表
    public function createConversionRules(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createConversionRules($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //客源跟进表
    public function createCustomerFollow(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createCustomerFollow($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //客源/房源跟进记录提醒表
    public function createCFS(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createCFS($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //房源表
    public function createFollow(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createFollow($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //操作日志表 log
    public function createLog(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createLog($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //手机端 工作计划表 mobile_plan
    public function createMobilePlan(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createMobilePlan($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //公司房客自动转移规则表 move_rule
    public function createMoveRule(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createMoveRule($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //公司规则状态更新表 move_rule_status
    public function createRuleStatus(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createRuleStatus($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //新闻公告表 news
    public function createNews(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createNews($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //房图片 room_img_url
    public function createImgUrl(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createImgUrl($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //房子信息表 room_info
    public function createRoomInfo(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createRoomInfo($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //楼盘字典表 room_wordbook
    public function createWordBook(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createWordBook($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //楼盘字典对应的栋座详细信息表 room_wordbook_info
    public function createWordBookInfo(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createWordBookInfo($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //员工考勤表 staff_attendance
    public function createStaffAttendance(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createStaffAttendance($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //公司内部员工论坛表 staff_forum
    public function createStaffForum(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createStaffForum($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //内部员工评论表 staff_forum_comment
    public function createStaffForumComment(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createStaffForumComment($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

    //中介公司员工 工作总结表 work_summary
    public function createWorkSummary(Request $request){
        $params = $request->all();
        $vali   = AdminVail::create($params);
        if (!$vali) {
            return $this->error(Error::PARAM_MISSING);
        }
        $status = CreateTable::createWorkSummary($params['c_id']);
        if($status === -1){
            return $this->success('ok', '表已存在，请勿再次创建');
        }
        if (!$status) {
            return $this->error(Error::CREATE_TABLE_ERROR);
        }
        return $this->success('ok', '创建成功');
    }

}